<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子28-ES6/7常用语法介绍</title>
    </head>

    <body>
        <pre>
            <code>
                // 例子28

                const foo = 'bar';
                const baz = {foo};
                console.log(baz); // {foo: "bar"}

                // 等同于
                const baz = {foo: foo};

                //--------------------------------------------------------------------------

                function f(x, y) {
                    return {x, y};
                }
                f(1, 2); // {x: 1, y: 2}

                // 等同于
                function f(x, y) {
                    return {x:x, y:y};
                }
                f(1, 2); // {x: 1, y: 2}

                //--------------------------------------------------------------------------

                const o = {
                    sayHello() {
                        return "Hello!";
                    }
                }

                // 等同于
                const o = {
                    sayHello: function() {
                        return "Hello!";
                    }
                }

                //--------------------------------------------------------------------------

                const cart = {
                    _wheels: 4,

                    get wheels () {
                        return this._wheels;
                    },

                    set wheels (value) {
                        if (value < this._wheels) {
                            throw new Error('数值太小了！');
                        }
                            this._wheels = value;
                    }
                }

                cart.wheels; // 4
                cart.wheels = 5;
                cart.wheels; // 5
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/28.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>

</html>